package com.ruoyi.common.core.domain.entity;

import com.ruoyi.common.core.domain.BaseEntity;
import com.ruoyi.common.xss.Xss;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.io.Serializable;

/**
 * 捷顺开放平台API请求参数实体类
 *
 * @author ruoyi
 */
public class ApiParam extends BaseEntity implements Serializable {
    private static final long serialVersionUID = 1L;

    /** 应用ID */
    @NotBlank(message = "应用ID不能为空")
    @Size(min = 0, max = 50, message = "应用ID长度不能超过50个字符")
    private String appId;

    /** 项目编码 */
    @NotBlank(message = "项目编码不能为空")
    @Size(min = 0, max = 50, message = "项目编码长度不能超过50个字符")
    private String projectCode;

    /** 能力编码 */
    @NotBlank(message = "能力编码不能为空")
    @Size(min = 0, max = 50, message = "能力编码长度不能超过50个字符")
    private String abilityCode;

    /** 接口编码 */
    @NotBlank(message = "接口编码不能为空")
    @Size(min = 0, max = 100, message = "接口编码长度不能超过100个字符")
    private String method;

    /** 签名类型 */
    @NotBlank(message = "签名类型不能为空")
    @Size(min = 0, max = 20, message = "签名类型长度不能超过20个字符")
    private String signType;

    /** 时间戳 */
    @NotNull(message = "时间戳不能为空")
    private Long timestamp;

    /** 字符集 */
    @NotBlank(message = "字符集不能为空")
    @Size(min = 0, max = 20, message = "字符集长度不能超过20个字符")
    private String charset;

    /** 返回格式 */
    @NotBlank(message = "返回格式不能为空")
    @Size(min = 0, max = 20, message = "返回格式长度不能超过20个字符")
    private String format;

    /** 业务参数（可以是Map、List或其他Java对象） */
    @Xss(message = "业务参数不能包含脚本字符")
    private Object bizContent;

    /** 签名结果 */
    private String sign;

    public ApiParam() {
        // 默认初始化时间戳
        this.timestamp = System.currentTimeMillis();
    }

    public String getAppId() {
        return appId;
    }

    public void setAppId(String appId) {
        this.appId = appId;
    }

    public String getProjectCode() {
        return projectCode;
    }

    public void setProjectCode(String projectCode) {
        this.projectCode = projectCode;
    }

    public String getAbilityCode() {
        return abilityCode;
    }

    public void setAbilityCode(String abilityCode) {
        this.abilityCode = abilityCode;
    }

    public String getMethod() {
        return method;
    }

    public void setMethod(String method) {
        this.method = method;
    }

    public String getSignType() {
        return signType;
    }

    public void setSignType(String signType) {
        this.signType = signType;
    }

    public Long getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(Long timestamp) {
        this.timestamp = timestamp;
    }

    public String getCharset() {
        return charset;
    }

    public void setCharset(String charset) {
        this.charset = charset;
    }

    public String getFormat() {
        return format;
    }

    public void setFormat(String format) {
        this.format = format;
    }

    /**
     * 获取业务参数对象
     * @return 业务参数对象，可以是Map、List或其他Java对象
     */
    public Object getBizContent() {
        return bizContent;
    }

    /**
     * 设置业务参数
     * @param bizContent 业务参数对象，可以是Map、List、JavaBean等
     */
    public void setBizContent(Object bizContent) {
        this.bizContent = bizContent;
    }

    public String getSign() {
        return sign;
    }

    public void setSign(String sign) {
        this.sign = sign;
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
                .append("appId", getAppId())
                .append("projectCode", getProjectCode())
                .append("abilityCode", getAbilityCode())
                .append("method", getMethod())
                .append("signType", getSignType())
                .append("timestamp", getTimestamp())
                .append("charset", getCharset())
                .append("format", getFormat())
                .append("bizContent", getBizContent())
                .append("sign", getSign())
                .append("createBy", getCreateBy())
                .append("createTime", getCreateTime())
                .append("updateBy", getUpdateBy())
                .append("updateTime", getUpdateTime())
                .toString();
    }
}
